// en en-us en-my en-sg en-ph en-kr
// zh zh-hk(繁体) zh-my  zh-sg
// ko ko-kr
// ru
const LANGUAGES = [
  { label: 'English', value: 'en', code: 'en', file: 'en.json' },
  { label: '中文', value: 'zh', code: 'zh', file: 'zh.json' },
  { label: '繁体中文', value: 'zh-hk', code: 'zh-hk', file: 'zh-hk.json' },
  { label: 'اللغة العربية', value: 'ar', code: 'ar', file: 'ar.json' },
  { label: 'Malaysia', value: 'ms', code: 'ms', file: 'ms.json' },
  { label: '한국어', value: 'ko', code: 'ko', file: 'ko.json' },
  { label: 'Русский', value: 'ru', code: 'ru', file: 'ru.json' },
  { label: 'हिन्दी', value: 'hi', code: 'hi', file: 'hi.json' },
  { label: 'Indonesia', value: 'id', code: 'id', file: 'id.json' },
  { label: 'español', value: 'es', code: 'es', file: 'es.json' },
  { label: 'Portuguese', value: 'pt', code: 'pt', file: 'pt.json' },
  { label: 'Français', value: 'fr', code: 'fr', file: 'fr.json' },
  { label: '日本语', value: 'ja', code: 'ja', file: 'ja.json' },
  { label: 'Nigerian', value: 'ng', code: 'ng', file: 'ng.json' },
]
const LANGUAGES_I18N = [
  { value: 'en', code: 'en', file: 'en.json', reqCode: 'en' },
  { value: 'zh', code: 'zh', file: 'zh.json', reqCode: 'zh-CN' },
  { value: 'zh-hk', code: 'zh-hk', file: 'zh-hk.json', reqCode: 'zh-TW' },
  { value: 'ms', code: 'ms', file: 'ms.json', reqCode: 'ms' },
  { value: 'hi', code: 'hi', file: 'hi.json', reqCode: 'hi' },
  { value: 'ar', code: 'ar', file: 'ar.json', reqCode: 'ar' },
  { value: 'ko', code: 'ko', file: 'ko.json', reqCode: 'ko' },
  { value: 'ru', code: 'ru', file: 'ru.json', reqCode: 'ru' },
  { value: 'id', code: 'id', file: 'id.json', reqCode: 'id' },
  { value: 'es', code: 'es', reqCode: 'es', file: 'es.json' },
  { value: 'pt', code: 'pt', reqCode: 'pt', file: 'pt.json' },
  { value: 'fr', code: 'fr', reqCode: 'fr', file: 'fr.json' },
  { value: 'ja', code: 'ja', reqCode: 'ja', file: 'ja.json' },
  { value: 'ng', code: 'ng', reqCode: 'en', file: 'ng.json' },
]
const DEFAULT_LOCALE = 'en'
export const useNuxtI18nConfig = () => {
  const i18nConfig = {
    locales: LANGUAGES_I18N.map((item) => ({
      language: item.value,
      code: item.code,
      file: item.file,
    })),
    baseUrl: '/',
    vueI18n: './i18n.config.ts',
    lazy: true,
    defaultLocale: DEFAULT_LOCALE,
    langDir: 'locales',
    detectBrowserLanguage: false,
    // detectBrowserLanguage: {
    //   useCookie: true,
    //   cookieKey: 'i18n_redirected', //切换语言的时候只需要设置这个cookie值 下次进入根路径也会直接跳转对应语言
    //   // 需要根路径判断一下新进来的语言和老语言是否一样
    //   redirectOn: 'root',
    // },
  }
  return {
    LANGUAGES,
    LANGUAGES_I18N,
    DEFAULT_LOCALE,
    i18nConfig,
  }
}
export const useNuxtHead = () => {
  return {
    htmlAttrs: {
      lang: 'en',
    },
    meta: [
      { charset: 'utf-8' },
      { name: 'theme-color', content: '#2a3032' },
      { name: 'renderer', content: 'webkit' },
      { name: 'og:site_name', content: 'BitTopup' },
      { name: 'og:type', content: 'website' },
      {
        name: 'viewport',
        content: 'width=device-width,initial-scale=1,minimum-scale=1,user-scalable=no',
      },
      { name: 'format-detection', content: 'telephone=no' },
    ],
    link: [
      { rel: 'preconnect', href: 'https://pic.bittopup.com' },
      { rel: 'preconnect', href: 'https://api.bittopup.com' },
      { rel: 'manifest', href: '/manifest.json' },
      { rel: 'dns-prefetch', href: 'https://pic.bittopup.com' },
      { rel: 'dns-prefetch', href: 'https://api.bittopup.com' },
      { rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' },
    ],
    script: [],
  }
}
export const useRouteRules = () => {
  const cacheTime = 120
  const spaRules = ['/pre-order', '/user', '/common/*', '/sso/*', '/user/*']
  const multipartLangSpaRules = spaRules.reduce((acc, key) => {
    acc[`${key}`] = {
      ssr: false,
      static: true,
      // swr: true,
    }
    LANGUAGES.forEach((item) => {
      acc[`/${item.value}${key}`] = {
        ssr: false,
        static: true,
        // swr: true,
      }
    })
    return acc
  }, {})
  const commonRouteRules = {
    '/zh-CN': { redirect: { to: '/zh', statusCode: 301 } },
    '/zh-TW': { redirect: { to: '/zh', statusCode: 301 } },
    '/zh-CN/**': { redirect: { to: '/zh/**', statusCode: 301 } },
    '/zh-TW/**': { redirect: { to: '/zh/**', statusCode: 301 } },

    '/en-us': { redirect: { to: '/', statusCode: 301 } },
    '/en-us/**': { redirect: { to: '/**', statusCode: 301 } },
    '/en-my': { redirect: { to: '/', statusCode: 301 } },
    '/en-my/**': { redirect: { to: '/**', statusCode: 301 } },
    '/en-sg': { redirect: { to: '/', statusCode: 301 } },
    '/en-sg/**': { redirect: { to: '/**', statusCode: 301 } },
    '/en-ph': { redirect: { to: '/', statusCode: 301 } },
    '/en-ph/**': { redirect: { to: '/**', statusCode: 301 } },
    '/en-kr': { redirect: { to: '/', statusCode: 301 } },
    '/en-kr/**': { redirect: { to: '/**', statusCode: 301 } },

    '/zh-my': { redirect: { to: '/zh', statusCode: 301 } },
    '/zh-my/**': { redirect: { to: '/zh/**', statusCode: 301 } },
    '/zh-sg': { redirect: { to: '/zh', statusCode: 301 } },
    '/zh-sg/**': { redirect: { to: '/zh/**', statusCode: 301 } },
  }
  return {
    devRouteRules: {
      ...commonRouteRules,
      ...multipartLangSpaRules,
    },
    prodRouteRules: {
      ...commonRouteRules,
      // 暂不配置
      '/**': {
        // headers: {
        //   'Cache-Control': `public, s-maxage=${cacheTime}, stale-while-revalidate=${3600 * 24 * 5}`,
        //   'CDN-Cache-Control': `public, s-maxage=${cacheTime}, stale-while-revalidate=${3600 * 24 * 5}`,
        // },
        // swr: cacheTime,
        // cache: {},
      },
      '/goods/**': {
        // headers: {
        //   'Cache-Control': `public, s-maxage=${cacheTime}, stale-while-revalidate=${3600 * 24 * 5}`,
        //   'CDN-Cache-Control': `public, s-maxage=${cacheTime}, stale-while-revalidate=${3600 * 24 * 5}`,
        // },
        // swr: cacheTime,
        // cache: {},
      },
      '/_nuxt/**': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      '/_ipx/**': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      '/v2/**': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      '/vantfont.woff': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      '/icon.png': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      '/logo.png': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      '/favicon.ico': {
        // swr: true,
        static: true,
        headers: {
          'Cache-Control': `public, max-age=${3600 * 24 * 365}`,
          'CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
          'Cloudflare-CDN-Cache-Control': `max-age=${3600 * 24 * 365}`,
        },
      },
      // ...multipartLangIndexRules,
      // ...multipartLangSwrRules,
      ...multipartLangSpaRules,
    },
  }
}
